package com.sqkj.dao;

import com.sqkj.entity.User;
import com.sqkj.entity.UserCard;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface UserDao {
    @Select("select count(*) from users where UserName=#{UserName}")
    public int UserCount(String UserName);
    @Select("select * from users where UserName=#{UserName}")
    public List<User> findByName(String UserName);
    @Select("select * from users")
    public List<User>findAll();
    @Select("select * from users where id=#{id}")
    public User findById(int id);
    @Insert("insert into users(openId ,wxName,UserName,Job,Phone,email,CNname,USname,Fax,Address,UserIcon) values(#{openId},#{wxName},#{UserName},#{Job},#{Phone},#{email},#{CNname},#{USname},#{Fax},#{Address},#{UserIcon})")
    @SelectKey(statement="select LAST_INSERT_ID()", keyProperty="id", before=false, resultType=int.class)
    public int add(User user);
    @Delete("delete from users where id=#{id}")
    public int deleteById(int id);
    @Update("update users set UserName=#{UserName},Job=#{Job},Phone=#{Phone},email=#{email},CNname=#{CNname},USname=#{USname},Fax=#{Fax},Address=#{Address} where id=#{id}")
    public int update(User user);

    @Select("select * from users where UserName like #{str} or Job like #{str} or Phone like #{str} or CNname like #{str}")
    public List<User> findLike(String str);
    @Select("select * from users where wxName=#{wxName}")
    public User findByWxName(@Param("wxName")String wxName);
    @Select("select * from users where openId=#{openId}")
    public User findByOpenId(@Param("openId")String openId);

}
